<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%
	String codeId = request.getParameter("codeId");
%>
	<script type="text/javascript">
	
			$(function(){
				//加载两个要使用json分页的组件
		        loadGird("frm", 1);
			})
				
			//对第一个frm的回调函数, 方法的命名规则为callback_+表单id	
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
		           row.find(".klId").attr("value",n.id);
		       	   row.find(".klName").text(n.name);
		           row.find(".klRemarks").text(n.remarks);
		           row.find(".kledituser").attr("href","<%=path %>/sys/role/get/roleUsers?codeId=<%=codeId %>&roleId="+n.id);
		           row.find(".kleditmodule").attr("href","<%=path %>/sys/role/get/roleModules?codeId=<%=codeId %>&roleId="+n.id);
		           row.attr("id","ready"+i);//改变绑定好数据的行的id
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");//添加到模板的容器中
		       });   
			}
			
			var delroles = function(){
				var options = {
				type: 'POST',
				async: false,
				dataType: 'content-type',
				success: function(msg) {
					alert("成功删除"+msg+"条记录");
					window.location.reload();
				}
				}
				if(confirm('您确认要删除吗？')){
					//提交form
					document.getElementById("frm").action="<%=path %>/sys/role/delroles";
					$('#frm').ajaxSubmit(options);
				}
			}
			
			function addrole(){
				opendailog("{src:'<%=path %>/sys/role/toEdit/0?codeId=<%=codeId %>',title:'角色属性',width:600,height:300,savefunc:'savefunc'}",window);
			}
			
			function modifyrole(){
				if(checkOnlySel()){
					opendailog("{src:'<%=path %>/sys/role/toEdit/"+getCheckedObj("chk")[0].value+"?codeId=<%=codeId %>',title:'角色属性',width:600,height:300,savefunc:'savefunc'}",window);
				}
			}
			
			function savefunc(frame){
				var retv = frame.contentWindow.save()
				if(retv=="success"){
					alertMsg("保存成功！");
					reloadGrid("frm", 1);
				}
				return retv;
			}
	</script>
<!-- 测试的表单1 frm1 请求json的action请求必须填写 -->
<form name="frm" method="post"
	action="<%=path %>/sys/role/list?codeId=<%=codeId %>" id="frm">
	<table width="100%">
			<tr>
				<td height="2px"></td>
			</tr>
			<tr><td align="right">
				<input type="button" onclick="addrole();" class="button4_nbw" value="添加" />
				<input type="button" onclick="modifyrole();" class="button4_nbw" value="修改" />
				<input type="button" onclick="delroles();" class="button4_nbw" value="删除" />
				&nbsp;&nbsp;
				</td>
			</tr>
		</table>
	<center>
	<table><tr><td height="2px"></td></tr></table>
	<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
		<thead class="th_nbw">
			<tr>
				<td width="40px">
					<input type="checkbox" class="allCheck" />
				</td>
				<td>
					角色名称
				</td>
				<td>
					备注
				</td>
				<td>
					操 作
				</td>
			</tr>
		</thead>
		<tbody>
			<tr class="template klId">
				<td width="40px" class="idCheck">
					<input type="checkbox" name="chk" class="klId" />
				</td>
				<td class="klName niceTable-left"></td>
				<td class="klRemarks niceTable-left"></td>
				<td >
					<a href=""  class="kledituser"/>维护用户</a>
					&nbsp;&nbsp;
					<a href=""  class="kleditmodule"/>角色授权</a>
				</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td style="border-right: none">
					<img class="loading"
						src="<%=imgPath %>/large-loading.gif" width="20px"
						class="hidden" />
				</td>
				<td colspan="4" style="border-left: none" class="txtRight">
					<span class="pagediv"></span>
				</td>
			</tr>
		</tfoot>
	</table>
	</center>
</form>